<template>
  <el-dropdown trigger="click" @command="handleSetSize">
    <div>
      <svg-icon class-name="size-icon" :style="{color:themeColor}" icon-class="size" style="font-size:18px;" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of sizeOptions" :class="{active:size===item.value}" :key="item.value" :disabled="size===item.value" :command="item.value">
        <span>{{ item.label }}</span>
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import { changeFontStyle,cleanFontStyle } from "../../utils/fontSetting";
import { mapGetters } from 'vuex'
export default {
  data()
  {
    return {
      sizeOptions: [
        { label: '超大', value: 'large' },
        { label: '大', value: 'medium' },
        { label: '中', value: 'small' },
        { label: '小', value: 'mini' },
        { label: '标准', value: 'biaozhun' }
      ]
    }
  },
  computed: {
    size()
    {
      return this.$store.getters.size
    },
    ...mapGetters([
      'themeColor',"fontSize"
    ]),
  },
  methods: {
    handleSetSize(size)
    {

        this.$ELEMENT.size = size
        this.$store.dispatch('app/setSize', size)
        this.refreshView()
        this.$message({
          message: '设置成功',
          type: 'success'
        })
        if(size=='biaozhun'){
          cleanFontStyle()
        }else{
          changeFontStyle(size);
        }

    },
    refreshView()
    {
      // In order to make the cached page re-rendered
      this.$store.dispatch('tagsView/delAllCachedViews', this.$route)

      const { fullPath } = this.$route

      this.$nextTick(() =>
      {
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.size-icon {
  color: #fff;
}

.el-dropdown-menu__item.active {
  background-color: #e8f4ff;
  color: #46a6ff;
}
</style>